/*
 * JavaMethodComparerView.java
 */
package util;

import java.awt.Dimension;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class JavaMethodComparerView extends FrameView {
    //Create a file chooser
    final JFileChooser jFileChooser;
    private String class1,  class2;

    public JavaMethodComparerView(SingleFrameApplication app) {
        super(app);
        jFileChooser = new JFileChooser();
        JavaFileFilter filter = new JavaFileFilter();
        filter.addExtension("java");
        filter.setDescription("Java source files");
        jFileChooser.setFileFilter(filter);

        initComponents();
        getFrame().setResizable(false);

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = JavaMethodComparer.getApplication().getMainFrame();
            aboutBox = new JavaMethodComparerAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        JavaMethodComparer.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        class1TextField = new javax.swing.JTextField();
        class2TextField = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jScrollPane1 = new javax.swing.JScrollPane();
        methodsInClass1 = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        methodsInClass2 = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        commonMethods = new javax.swing.JTextArea();
        jButton3 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        mainPanel.setName("mainPanel"); // NOI18N

        class1TextField.setSize(new Dimension(336,12));
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(util.JavaMethodComparer.class).getContext().getResourceMap(JavaMethodComparerView.class);
        class1TextField.setText(resourceMap.getString("class1TextField.text")); // NOI18N
        class1TextField.setName("class1TextField"); // NOI18N

        class2TextField.setSize(new Dimension(336,12));
        class2TextField.setText(resourceMap.getString("class2TextField.text")); // NOI18N
        class2TextField.setName("class2TextField"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        statusMessageLabel.setText(resourceMap.getString("statusMessageLabel.text")); // NOI18N
        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setBackground(resourceMap.getColor("statusAnimationLabel.background")); // NOI18N
        statusAnimationLabel.setText(resourceMap.getString("statusAnimationLabel.text")); // NOI18N
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        methodsInClass1.setColumns(20);
        methodsInClass1.setFont(new java.awt.Font("Courier New 7", 0, 10));
        methodsInClass1.setRows(5);
        methodsInClass1.setName("methodsInClass1"); // NOI18N
        jScrollPane1.setViewportView(methodsInClass1);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        methodsInClass2.setColumns(20);
        methodsInClass2.setFont(new java.awt.Font("Courier New 7", 0, 10));
        methodsInClass2.setRows(5);
        methodsInClass2.setName("methodsInClass2"); // NOI18N
        jScrollPane2.setViewportView(methodsInClass2);

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        commonMethods.setBackground(new java.awt.Color(204, 204, 204));
        commonMethods.setColumns(20);
        commonMethods.setFont(new java.awt.Font("Courier New", 1, 10));
        commonMethods.setRows(5);
        commonMethods.setName("commonMethods"); // NOI18N
        jScrollPane3.setViewportView(commonMethods);

        jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                        .addComponent(statusAnimationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(class2TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
                            .addComponent(class1TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 497, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(class1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(class2TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2))
                .addGap(10, 10, 10)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addGap(1, 1, 1)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(statusAnimationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(statusMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE))
                .addContainerGap())
        );

        mainPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {progressBar, statusAnimationLabel});

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(util.JavaMethodComparer.class).getContext().getActionMap(JavaMethodComparerView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int returnVal = jFileChooser.showOpenDialog(mainPanel);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = jFileChooser.getSelectedFile();
            //This is where a real application would open the file.
            class2 = file.getAbsolutePath();
            this.class2TextField.setText(class2);
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int returnVal = jFileChooser.showOpenDialog(mainPanel);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = jFileChooser.getSelectedFile();
            //This is where a real application would open the file.
            class1 = file.getAbsolutePath();
            this.class1TextField.setText(class1);
        }
}//GEN-LAST:event_jButton1ActionPerformed

    private String printList(ArrayList<String> methods1) {
        StringBuffer sb = new StringBuffer();
        Iterator iter = methods1.iterator();
        while (iter.hasNext()) {
            sb.append(iter.next());
            sb.append('\n');
        }
        return sb.toString();
    }

    private StringBuffer readFileToStringBuffer(File f) {
        String line = null;
        StringBuffer lines = new StringBuffer();
        try {
            FileReader fileReader = new FileReader(f);
            BufferedReader bufferedReader = new BufferedReader(fileReader);

            while ((line = bufferedReader.readLine()) != null) {
                lines.append(line);
                lines.append('\n');
            }
            bufferedReader.close();
        } catch (IOException ex) {
            Logger.getLogger(JavaMethodComparerView.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lines;
    }
    //final String methodRegexPattern="\\w+ +\\w+ *\\([^\\)]*\\) *\\{";
    final String methodRegexPattern = "\\w+ +\\w+ *\\([^\\)]*\\)";
    final Pattern pattern = Pattern.compile(methodRegexPattern, Pattern.MULTILINE);

    String fixMethodname(String method) {
        method = method.trim();
        method = method.replaceAll("\\n", "");
        method = method.replaceAll("\\t", "");
        method = method.replaceAll("  ", " ");

        //also remove parameter names
        method = removeParameterNames(method);
        return method;
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if (class1TextField.getText().length() > 0 && class2TextField.getText().length() > 0) {
            this.statusMessageLabel.setText("Processing...");
            try {
                File file1 = new File(class1TextField.getText());
                File file2 = new File(class2TextField.getText());

                if (!file1.exists() || !file2.exists()) {
                    this.statusMessageLabel.setText("File Not found!");
                    return;
                }

                this.statusMessageLabel.setText("Reading files...");
                StringBuffer file1SB = readFileToStringBuffer(file1);
                StringBuffer file2SB = readFileToStringBuffer(file2);

                ArrayList<String> methods1 = new ArrayList();
                ArrayList<String> methods2 = new ArrayList();

                Matcher m = pattern.matcher(file1SB);
                while (m.find()) {
                    methods1.add(fixMethodname(m.group()));
                }
                Collections.sort(methods1);
                this.methodsInClass1.setText(printList(methods1));
                //System.out.println("Class1 methods: \n" + printList(methods1));

                m = pattern.matcher(file2SB);
                while (m.find()) {
                    methods2.add(fixMethodname(m.group()));
                }
                Collections.sort(methods2);
                this.methodsInClass2.setText(printList(methods2));
                //System.out.println("Class2 methods: \n" + printList(methods2));

                StringBuffer finalStatus= new StringBuffer();
                finalStatus.append("<html>Methods in Class1: <b>").append(methods1.size())
                        .append("</b><br/>Methods in Class2: <b>").append(methods2.size());
                methods2.retainAll(methods1);
                finalStatus.append("</b><br/>Common methods: <b>").append(methods2.size()).append("</b></html>");
                this.commonMethods.setText(printList(methods2));
                this.statusMessageLabel.setText(finalStatus.toString());

            } catch (Exception e) {
                e.printStackTrace();
            }

        } else {
            this.statusMessageLabel.setText("Invalid path");
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField class1TextField;
    private javax.swing.JTextField class2TextField;
    private javax.swing.JTextArea commonMethods;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTextArea methodsInClass1;
    private javax.swing.JTextArea methodsInClass2;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;

    /**
     * sample input: com.avnet.quest.persistencerecord.custom.QuoteLineSubPK
     * sample output QuoteLineSubPK
     * @param classWithPackage
     * @return
     */
    private String removePackageFromClassStr(String input) {
        if (input.lastIndexOf(".") != -1) {
            return input.substring(input.lastIndexOf(".") + 1, input.length());
        } else {
            return input;
        }
    }

    /**
     * example input: public ExceptionReasonPSQuoteListPR(String exceptionReasonCd,String exceptionReasonDs, String exceptionReasonNm,String exceptionTypeCd)
     * example output:  public ExceptionReasonPSQuoteListPR(String,String,String,String)
     * @param method
     * @return
     */
    private String removeParameterNames(String method) {
        /*steps:
         * get the string from the start till '(' as methodname
         * get the string between ( and ) as parameters
         * tokenize parameters using ',' as delimiter. Get the string from the start of each token till space.
         * return methodname+ ( + tokens+ )
         */
        //System.out.println("In method="+method);
        StringBuffer signature = new StringBuffer();
        String methodname = method.substring(0, method.indexOf("("));
        String parameters = method.substring(method.indexOf("(") + 1, method.indexOf(")"));
        StringTokenizer tokenizer = new StringTokenizer(parameters, ",");
        StringBuffer sigparameters = new StringBuffer();
        String token;
        while (tokenizer.hasMoreTokens()) {
            token = tokenizer.nextToken().trim();
            if (sigparameters.length() > 0) {
                sigparameters.append(",");
            }
            //System.out.println("token='"+token+"'");
            if (token.indexOf(" ") != -1) {
                sigparameters.append(removePackageFromClassStr(token.substring(0, token.indexOf(" "))));
            } else {
                sigparameters.append(token);
            }
        }
        signature.append(methodname).append('(').append(sigparameters).append(')');
        //System.out.println("out method="+signature);
        return signature.toString();
    }
}
